/*
 * Copyright (C) 2019 ByteDance Inc
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package com.bytedance.scene.ui;


import com.bytedance.scene.NavigationSceneUtility;
import com.bytedance.scene.ResourceTable;
import com.bytedance.scene.Scene;
import com.bytedance.scene.SceneDelegate;
import ohos.aafwk.ability.fraction.FractionAbility;
import ohos.aafwk.content.Intent;
import ohos.aafwk.content.IntentParams;
import ohos.agp.utils.Color;

/**
 * Created by JiangQi on 8/24/18.
 */
public abstract class SceneAbility extends FractionAbility {
    private SceneDelegate mDelegate;

    @Override
    protected void onStart(Intent intent) {
        super.onStart(intent);
        getWindow().setStatusBarColor(Color.getIntColor("#2E409F"));
        super.setUIContent(ResourceTable.Layout_navigation_scene);
        IntentParams arguments = getHomeSceneArguments(intent);
        this.mDelegate = NavigationSceneUtility.setupWithActivity(this, getHomeSceneClass())
                .rootSceneArguments(arguments)
                .supportRestore(supportRestore()).build();
    }

    @Override
    public void onBackPressed() {
        if (!this.mDelegate.onBackPressed()) {
            super.onBackPressed();
        }
    }

    
    protected abstract Class<? extends Scene> getHomeSceneClass();

    protected abstract boolean supportRestore();

    
    protected IntentParams getHomeSceneArguments(Intent intent) {
        return null;
    }
}
